#ifndef GIFDECODER_H
#define GIFDECODER_H

#include "gifblock.h"
#include "gifextension.h"
#include "gifframe.h"
#include "gifheader.h"
#include <QIODevice>
#include <QObject>

namespace WingGif {

enum class FrameDisposalMethod {
  None = 0,
  DoNotDispose = 1,
  RestoreBackground = 2,
  RestorePrevious = 3
};

struct FrameMetadata {
  int left;
  int top;
  int width;
  int height;
  int delay; // ms
  FrameDisposalMethod disposalMethod;
};

class WINGEXPORT GifDecoder : public QObject {
  Q_OBJECT

  Q_PROPERTY(GifHeader *header READ header)
  Q_PROPERTY(QVector<GifColor> globalColorTable READ globalColorTable)
  Q_PROPERTY(QList<GifFrame *> frames READ frames)
  Q_PROPERTY(QList<GifExtension *> extensions READ extensions)
  Q_PROPERTY(ushort repeatCount READ repeatCount)

public:
  explicit GifDecoder(QObject *parent = nullptr);

  bool decode(QIODevice *stream);

  GifHeader *header();
  QVector<GifColor> globalColorTable();
  QList<GifFrame *> frames();
  QList<GifExtension *> extensions();
  ushort repeatCount();

private:
  bool readFrames(QIODevice *stream);

private:
  GifHeader *_header;
  QVector<GifColor> _globalColorTable;
  QList<GifFrame *> _frames;
  QList<GifExtension *> _extensions;
  ushort _repeatCount;
};

} // namespace WingGif

#endif // GIFDECODER_H
